#include "ParamUnitSetView.h"
#include "ui_ParamUnitSetForm.h"
#include <QSqlRecord>
#include <QSqlQuery>
#include <QDebug>
#include "GlobalApi/SqliteDb.h"
#include "Auxiliary/View/MessageBoxDialog.h"


const char *unitInx[29]={"wbc","neu1","lym1","mon1","eos1","bas1","neu2","lym2","mon2","eos2","bas2","aly1","aly2","lic1","lic2", \
                          "rbc","hgb","hct","mcv","mch","mchc","rdwcv","rdwsd","plt","mpv","pdw","pct","plcc","plcr"};

const char *unitForm[29]={"wbcfm","neu1fm","lym1fm","mon1fm","eos1fm","bas1fm","neu2fm","lym2fm","mon2fm","eos2fm","bas2fm","aly1fm","aly2fm","lic1fm","lic2fm", \
                          "rbcfm","hgbfm","hctfm","mcvfm","mchfm","mchcfm","rdwcvfm","rdwsdfm","pltfm","mpvfm","pdwfm","pctfm","plccfm","plcrfm"};

ParamUnitSetView::ParamUnitSetView(QWidget *parent) :
    QWidget(parent), ui(new Ui::ParamUnit)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);  // 隐藏标题设置为顶层显示
    tc = QTextCodec::codecForName("UTF-8");
    paramUnitsDao = new ParamUnitsDao();
    initUi();
}

ParamUnitSetView::~ParamUnitSetView()
{
    delete ui;
}

void ParamUnitSetView::initUi()
{
    initModel();
    initTable();
    initConnect();
    m_selectFlg = 0;
    setUnitSelectShow(0);

}

void ParamUnitSetView::initModel()
{
    // 当前使用的设置单位
    pCurModel = new QSqlTableModel(this, SqliteDb::getInstance()->getDB());
    pCurModel->setTable("UnitsTable");
    pCurModel->select();
    pCurModel->setEditStrategy(QSqlTableModel::OnManualSubmit);

    // 默认的单位
    pDefModel = new QSqlTableModel(this, SqliteDb::getInstance()->getDB());
    pDefModel->setTable("UnitsNationTable");
    pDefModel->select();
    pDefModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
}

void ParamUnitSetView::initTable()
{
    int i=0,j=0;

    const QString unitTile[3]={tr("参数"), tr("单位"), tr("格式")};
    const char *unitItem[30]={"WBC","Neu#","Lym#","Mon#","Eos#","Bas#","Neu%","Lym%","Mon%","Eos%","Bas%","*ALY#","*ALY%","*LIC#","*LIC%", \
                              "RBC","HGB","HCT","MCV","MCH","MCHC","RDW-CV","RDW-SD","PLT","MPV","PDW","PCT","P-LCC","P-LCR",""};

    ui->tableWidget_unit1->setColumnCount(3);
    ui->tableWidget_unit1->setRowCount(20);
    ui->tableWidget_unit1->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    ui->tableWidget_unit1->verticalHeader()->setResizeMode(QHeaderView::Fixed);

    ui->tableWidget_unit1->setSelectionMode(QAbstractItemView::SingleSelection); //选择
    ui->tableWidget_unit1->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置不可编辑
    ui->tableWidget_unit1->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
    ui->tableWidget_unit1->verticalHeader()->hide();
    ui->tableWidget_unit1->horizontalHeader()->hide();

    ui->tableWidget_unit2->setColumnCount(3);
    ui->tableWidget_unit2->setRowCount(18);
    ui->tableWidget_unit2->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    ui->tableWidget_unit2->verticalHeader()->setResizeMode(QHeaderView::Fixed);
    ui->tableWidget_unit2->setSelectionMode(QAbstractItemView::SingleSelection); //选择
    ui->tableWidget_unit2->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置不可编辑
    ui->tableWidget_unit2->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
    ui->tableWidget_unit2->verticalHeader()->hide();
    ui->tableWidget_unit2->horizontalHeader()->hide();


    QString stylesheettableWidget_listing = "QTableWidget{background-color:#e2f7eb;"
                                            "alternate-background-color: #ffffff;"
                                            "border:1px solid#C9C9C9;"
                                            "color: rgb(0, 0, 0);"
                                            "selection-color: rgb(255, 255, 255);"
                                            "selection-background-color: rgb(32, 131, 95);}";

    ui->tableWidget_unit1->setAlternatingRowColors(true);//间隔显示颜色
    ui->tableWidget_unit1->setStyleSheet(stylesheettableWidget_listing);
    ui->tableWidget_unit2->setAlternatingRowColors(true);//间隔显示颜色
    ui->tableWidget_unit2->setStyleSheet(stylesheettableWidget_listing);

    for(i = 0;i<3;++i)
    {
        ui->tableWidget_unit1->setItem(0,i,new QTableWidgetItem(unitTile[i]));
        ui->tableWidget_unit1->item(0,i)->setFlags( Qt::ItemIsSelectable );
        ui->tableWidget_unit1->item(0,i)->setTextColor( QColor(0, 0, 0) );
        ui->tableWidget_unit1->item(0,i)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_unit1->item(0,i)->setBackgroundColor(QColor(102, 204, 153));
        ui->tableWidget_unit1->item(0,i)->setTextColor(QColor(0, 0, 0));
        //ui->tableWidget_unit->item(0,i)->setFont( QFont( "Times", 10, QFont::Bold ) );  //将字体加粗
        ui->tableWidget_unit2->setItem(0,i,new QTableWidgetItem(unitTile[i]));
        ui->tableWidget_unit2->item(0,i)->setFlags( Qt::ItemIsSelectable );
        ui->tableWidget_unit2->item(0,i)->setTextColor( QColor(0, 0, 0) );
        ui->tableWidget_unit2->item(0,i)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_unit2->item(0,i)->setBackgroundColor(QColor(102, 204, 153));
        ui->tableWidget_unit2->item(0,i)->setTextColor(QColor(0, 0, 0));

    }


        for(i = 1;i<20;++i)
        {
            if(i<16)
            {
                ui->tableWidget_unit1->setItem(i,0, new QTableWidgetItem(tc->toUnicode(unitItem[i-1])));

                ui->tableWidget_unit2->setItem(i,0, new QTableWidgetItem(tc->toUnicode(unitItem[i+14])));
                ui->tableWidget_unit2->item(i,0)->setFlags( Qt::ItemIsSelectable );
                ui->tableWidget_unit2->item(i,0)->setFlags( Qt::ItemIsEditable );
                ui->tableWidget_unit2->item(i,0)->setTextColor( QColor(0, 0, 0) );
                ui->tableWidget_unit2->item(i,0)->setTextAlignment(Qt::AlignCenter);
                ui->tableWidget_unit2->item(i,0)->setBackgroundColor(QColor(102, 204, 153));
                ui->tableWidget_unit2->item(i,0)->setTextColor(QColor(0, 0, 0));
            }
            else
            {
                ui->tableWidget_unit1->setItem(i,0, new QTableWidgetItem(""));
                if(i < 18)
                {
                    ui->tableWidget_unit2->setItem(i,0, new QTableWidgetItem(""));
                    ui->tableWidget_unit2->item(i,0)->setFlags( Qt::ItemIsSelectable );
                    ui->tableWidget_unit2->item(i,0)->setFlags( Qt::ItemIsEditable );
                    ui->tableWidget_unit2->item(i,0)->setTextColor( QColor(0, 0, 0) );
                    ui->tableWidget_unit2->item(i,0)->setTextAlignment(Qt::AlignCenter);
                    ui->tableWidget_unit2->item(i,0)->setBackgroundColor(QColor(102, 204, 153));
                    ui->tableWidget_unit2->item(i,0)->setTextColor(QColor(0, 0, 0));
                }

            }
            ui->tableWidget_unit1->item(i,0)->setFlags( Qt::ItemIsSelectable );
            ui->tableWidget_unit1->item(i,0)->setFlags( Qt::ItemIsEditable );
            ui->tableWidget_unit1->item(i,0)->setTextColor( QColor(0, 0, 0) );
            //ui->tableWidget_unit->item(i,j)->setFont( QFont( "Helvetica", 10, QFont::Bold ) );  //将字体加粗
            ui->tableWidget_unit1->item(i,0)->setTextAlignment(Qt::AlignCenter);
            ui->tableWidget_unit1->item(i,0)->setBackgroundColor(QColor(102, 204, 153));
            ui->tableWidget_unit1->item(i,0)->setTextColor(QColor(0, 0, 0));
        }


      for(int j=1;j<3;j++)
      {
          for(i = 1;i<16;++i)
          {

              ui->tableWidget_unit1->setItem(i,j, new QTableWidgetItem(""));
              ui->tableWidget_unit1->item(i,j)->setTextColor( QColor(0, 0, 0) );
              //ui->tableWidget_unit->item(i,j)->setFont( QFont( "Helvetica", 10, QFont::Bold ) );  //将字体加粗
              ui->tableWidget_unit1->item(i,j)->setTextAlignment(Qt::AlignCenter);

              ui->tableWidget_unit2->setItem(i,j, new QTableWidgetItem(""));
              ui->tableWidget_unit2->item(i,j)->setTextColor( QColor(0, 0, 0) );
              ui->tableWidget_unit2->item(i,j)->setTextAlignment(Qt::AlignCenter);

              if(j==2)
              {
                  ui->tableWidget_unit1->item(i,j)->setFlags( Qt::ItemIsSelectable );
                  ui->tableWidget_unit2->item(i,j)->setFlags( Qt::ItemIsSelectable );
              }
          }

          for(int i=0;i<4;i++)
          {
              ui->tableWidget_unit1->setItem(16+i,j, new QTableWidgetItem(""));
              ui->tableWidget_unit1->item(16+i,j)->setTextColor( QColor(0, 0, 0) );
              ui->tableWidget_unit1->item(16+i,j)->setTextAlignment(Qt::AlignCenter);
              ui->tableWidget_unit1->item(16+i,j)->setFlags( Qt::ItemIsSelectable );
          }

          for(int i=0;i<2;i++)
          {
              ui->tableWidget_unit2->setItem(16+i,j, new QTableWidgetItem(""));
              ui->tableWidget_unit2->item(16+i,j)->setTextColor( QColor(0, 0, 0) );
              ui->tableWidget_unit2->item(16+i,j)->setTextAlignment(Qt::AlignCenter);
              ui->tableWidget_unit2->item(16+i,j)->setFlags( Qt::ItemIsSelectable );
          }
      }
    ui->tableWidget_unit2->item(15,1)->setFlags( Qt::ItemIsSelectable );

    for(int i=0;i<4;i++)
    {
        ui->tableWidget_unit1->hideRow(16+i);
    }
    for(int i=0;i<2;i++)
    {
        ui->tableWidget_unit2->hideRow(16+i);
    }
}

void ParamUnitSetView::initConnect()
{
    connect(ui->tableWidget_unit1, SIGNAL(cellPressed(int , int )),this,SLOT(unitChoice1( int  , int )) );
    connect(ui->tableWidget_unit2, SIGNAL(cellPressed(int ,int )),this,SLOT(unitChoice2( int , int )) );
    connect(ui->comboBox_unitNation, SIGNAL( activated(int)),this,SLOT(unitNationChange( int )) );

    connect(ui->radioButton_unit1, SIGNAL(clicked()),this,SLOT(radioUnitSelect1() ) );
    connect(ui->radioButton_unit2, SIGNAL(clicked()),this,SLOT(radioUnitSelect2() ) );
    connect(ui->radioButton_unit3, SIGNAL(clicked()),this,SLOT(radioUnitSelect3() ) );
    connect(ui->radioButton_unit4, SIGNAL(clicked()),this,SLOT(radioUnitSelect4() ) );
}

void ParamUnitSetView::showEvent(QShowEvent *e)
{
   ui->comboBox_unitNation->setCurrentIndex(0); //先默认一个初始值，后面补充完成
   m_selectFlg = 0;
   ui->tableWidget_unit1->clearSelection(); // 设置非选中
   ui->tableWidget_unit2->clearSelection(); // 设置非选中

   m_UnitsSystem = ui->comboBox_unitNation->currentIndex();
   readParamUnitsInfo(paramUnitsDao);  //读取单位信息
   radioButton_clearCheck();
   setUnitSelectShow(0);
   refresh_units_display();

}


void ParamUnitSetView::closeEvent(QCloseEvent *event)
{


}

void ParamUnitSetView::readParamUnitsInfo(ParamUnitsDao *dao)
{
   dao->unitsSystem = m_UnitsSystem;

   int recordRow = m_UnitsSystem;
   QSqlRecord record = pCurModel->record(recordRow);

   for(int i = 0; i < 29; i++)
   {
       dao->units[i] = record.value(unitInx[i]).toString();
       dao->unitsForm[i] = record.value(unitForm[i]).toString();
   }
}

void ParamUnitSetView::setParamUnitsInfo()
{


}

void ParamUnitSetView::on_Btn_default_clicked()
{
    m_UnitsSystem = ui->comboBox_unitNation->currentIndex();  // 获取单位进制
    if(m_UnitsSystem < 0)
    {
        qDebug()<<"UnitsSystem error!";
        return;
    }

    paramUnitsDao->unitsSystem = m_UnitsSystem;

    int recordRow = m_UnitsSystem;
    QSqlRecord record = pDefModel->record(recordRow);

    for(int i = 0; i < 29; i++)
    {
        paramUnitsDao->units[i] = record.value(unitInx[i]).toString();
        paramUnitsDao->unitsForm[i] = record.value(unitForm[i]).toString();
    }

    refresh_units_display();  // 刷新表格单位显示
}

void ParamUnitSetView::refresh_units_display()
{
    //左侧表格15个参数
    for(int i = 1; i < 16; i++)
    {
        ui->tableWidget_unit1->item(i, 1)->setText(paramUnitsDao->units[i-1]);
        ui->tableWidget_unit1->item(i, 2)->setText(paramUnitsDao->unitsForm[i-1]);
    }

    // 右侧表格有14个参数
    for(int i = 1; i < 15; i++)
    {
        ui->tableWidget_unit2->item(i, 1)->setText(paramUnitsDao->units[15+i-1]);
        ui->tableWidget_unit2->item(i, 2)->setText(paramUnitsDao->unitsForm[15+i-1]);
    }
}

void ParamUnitSetView::radioButton_clearCheck()
{
   ui->radioButton_unit5->setChecked(true);
}

void ParamUnitSetView::unitNationChange(int index)
{
    MessageBoxDialog *messageBox = new MessageBoxDialog(this,\
                             QString(tr("是否保存？")));
    int result = messageBox->exec();
    if(result == QDialog::Accepted)
    {
       // 向单位数据库中写入数据
    } else {

    }

    m_UnitsSystem = index;  //更新单位进制
    readParamUnitsInfo(paramUnitsDao);  //读取单位信息
    radioButton_clearCheck();
    refresh_units_display();
}

void ParamUnitSetView::unitChoice1(int row, int column)
{

    if( 1 == column )
    {
        ui->tableWidget_unit2->clearSelection();

        if(row >= 1 && row <= 15){
            m_selectFlg = row;
        } else {
            m_selectFlg = 0;
        }

        switch (row)
        {
            case 1:
            {
                setUnitSelectShow(4);
                ui->radioButton_unit1->setText("10^9/L");
                ui->radioButton_unit2->setText("10^3/uL");
                ui->radioButton_unit3->setText("10^2/uL");
                ui->radioButton_unit4->setText("/nL");

                if(ui->tableWidget_unit1->item(row,column)->text() == "10^9/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^3/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^2/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "/nL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 2:
            {

                setUnitSelectShow(4);
                ui->radioButton_unit1->setText("10^9/L");
                ui->radioButton_unit2->setText("10^3/uL");
                ui->radioButton_unit3->setText("10^2/uL");
                ui->radioButton_unit4->setText("/nL");

                if(ui->tableWidget_unit1->item(row,column)->text() == "10^9/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^3/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^2/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "/nL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 3:
            {

                setUnitSelectShow(4);
                ui->radioButton_unit1->setText("10^9/L");
                ui->radioButton_unit2->setText("10^3/uL");
                ui->radioButton_unit3->setText("10^2/uL");
                ui->radioButton_unit4->setText("/nL");

                if(ui->tableWidget_unit1->item(row,column)->text() == "10^9/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^3/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^2/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "/nL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 4:
            {

                setUnitSelectShow(4);
                ui->radioButton_unit1->setText("10^9/L");
                ui->radioButton_unit2->setText("10^3/uL");
                ui->radioButton_unit3->setText("10^2/uL");
                ui->radioButton_unit4->setText("/nL");

                if(ui->tableWidget_unit1->item(row,column)->text() == "10^9/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^3/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^2/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "/nL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 5:
            {

                setUnitSelectShow(4);
                ui->radioButton_unit1->setText("10^9/L");
                ui->radioButton_unit2->setText("10^3/uL");
                ui->radioButton_unit3->setText("10^2/uL");
                ui->radioButton_unit4->setText("/nL");

                if(ui->tableWidget_unit1->item(row,column)->text() == "10^9/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^3/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^2/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "/nL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 6:
            {

                setUnitSelectShow(4);
                ui->radioButton_unit1->setText("10^9/L");
                ui->radioButton_unit2->setText("10^3/uL");
                ui->radioButton_unit3->setText("10^2/uL");
                ui->radioButton_unit4->setText("/nL");

                if(ui->tableWidget_unit1->item(row,column)->text() == "10^9/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^3/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^2/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "/nL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 7:
            {

                setUnitSelectShow(2);
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("   ");

                if(ui->tableWidget_unit1->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "")
                ui->radioButton_unit2->setChecked(true);

            }
            break;
            case 8:
            {

                setUnitSelectShow(2);
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("   ");

                if(ui->tableWidget_unit1->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "")
                ui->radioButton_unit2->setChecked(true);
            }
            break;
            case 9:
            {

                setUnitSelectShow(2);
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("   ");

                if(ui->tableWidget_unit1->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "")
                ui->radioButton_unit2->setChecked(true);
            }
            break;
            case 10:
            {

                setUnitSelectShow(2);
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("   ");

                if(ui->tableWidget_unit1->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "")
                ui->radioButton_unit2->setChecked(true);
            }
            break;
            case 11:
            {

                setUnitSelectShow(2);
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("   ");

                if(ui->tableWidget_unit1->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "")
                ui->radioButton_unit2->setChecked(true);
            }
            break;
            case 12:
            {

                setUnitSelectShow(4);
                ui->radioButton_unit1->setText("10^9/L");
                ui->radioButton_unit2->setText("10^3/uL");
                ui->radioButton_unit3->setText("10^2/uL");
                ui->radioButton_unit4->setText("/nL");

                if(ui->tableWidget_unit1->item(row,column)->text() == "10^9/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^3/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^2/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "/nL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 13:
            {

                setUnitSelectShow(2);
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("   ");

                if(ui->tableWidget_unit1->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "")
                ui->radioButton_unit2->setChecked(true);
            }
            break;
            case 14:
            {
                setUnitSelectShow(4);
                ui->radioButton_unit1->setText("10^9/L");
                ui->radioButton_unit2->setText("10^3/uL");
                ui->radioButton_unit3->setText("10^2/uL");
                ui->radioButton_unit4->setText("/nL");

                if(ui->tableWidget_unit1->item(row,column)->text() == "10^9/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^3/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "10^2/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "/nL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 15:
            {

                setUnitSelectShow(2);
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("   ");

                if(ui->tableWidget_unit1->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit1->item(row,column)->text() == "")
                ui->radioButton_unit2->setChecked(true);
            }
            break;
        }
    }
}

void ParamUnitSetView::unitChoice2(int row, int column)
{
    if( column == 1 )
    {
        ui->tableWidget_unit1->clearSelection();

        if(row >= 1 && row <= 14)
        {
            m_selectFlg = 15+row;
        }

        switch (row)
        {
            case 1:
            {

                setUnitSelectShow( 4 );
                ui->radioButton_unit1->setText("10^12/L");
                ui->radioButton_unit2->setText("10^6/uL");
                ui->radioButton_unit3->setText("10^4/uL");
                ui->radioButton_unit4->setText("/pL");

                if(ui->tableWidget_unit2->item(row,column)->text() == "10^12/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "10^6/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "10^4/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "/pL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 2:
            {

                setUnitSelectShow( 3 );
                ui->radioButton_unit1->setText("g/L");
                ui->radioButton_unit2->setText("g/dL");
                ui->radioButton_unit3->setText("mmol/L");

                if(ui->tableWidget_unit2->item(row,column)->text() == "g/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "g/dL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "mmol/L")
                ui->radioButton_unit3->setChecked(true);

            }
            break;
            case 3:  //hct
            {

                setUnitSelectShow( 3 );
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("L/L");
                ui->radioButton_unit3->setText("   ");

                if(ui->tableWidget_unit2->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "L/L")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "")
                ui->radioButton_unit3->setChecked(true);

            }
            break;
            case 4:  //mcv
            {

                setUnitSelectShow( 2 );
                ui->radioButton_unit1->setText("fL");
                ui->radioButton_unit2->setText("um^3");

                if(ui->tableWidget_unit2->item(row,column)->text() == "fL")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "um^3")
                ui->radioButton_unit2->setChecked(true);

            }
            break;
            case 5:
            {

                setUnitSelectShow( 3 );
                ui->radioButton_unit1->setText("pg");
                ui->radioButton_unit2->setText("fmol");
                ui->radioButton_unit3->setText("amol");

                if(ui->tableWidget_unit2->item(row,column)->text() == "pg")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "fmol")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "amol")
                ui->radioButton_unit3->setChecked(true);

            }
            break;
            case 6:   //mchc
            {

                setUnitSelectShow( 3 );
                ui->radioButton_unit1->setText("g/L");
                ui->radioButton_unit2->setText("g/dL");
                ui->radioButton_unit3->setText("mmol/L");

                if(ui->tableWidget_unit2->item(row,column)->text() == "g/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "g/dL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "mmol/L")
                ui->radioButton_unit3->setChecked(true);

            }
            break;
            case 7:  //RDW-CV
            {

                setUnitSelectShow( 2 );
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("   ");

                if(ui->tableWidget_unit2->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "")
                ui->radioButton_unit2->setChecked(true);

            }
            break;
            case 8:  //RDW-SD
            {

                setUnitSelectShow( 2 );
                ui->radioButton_unit1->setText("fL");
                ui->radioButton_unit2->setText("um^3");

                if(ui->tableWidget_unit2->item(row,column)->text() == "fL")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "um^3")
                ui->radioButton_unit2->setChecked(true);
            }
            break;
            case 9:  //PLT
            {

                setUnitSelectShow( 4 );
                ui->radioButton_unit1->setText("10^9/L");
                ui->radioButton_unit2->setText("10^3/uL");
                ui->radioButton_unit3->setText("10^4/uL");
                ui->radioButton_unit4->setText("/nL");

                if(ui->tableWidget_unit2->item(row,column)->text() == "10^9/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "10^3/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "10^4/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "/nL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 10:  //MPV
            {

                setUnitSelectShow( 2 );
                ui->radioButton_unit1->setText("fL");
                ui->radioButton_unit2->setText("um^3");

                if(ui->tableWidget_unit2->item(row,column)->text() == "fL")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "um^3")
                ui->radioButton_unit2->setChecked(true);

            }
            break;
            case 11:  //PDW
            {

                setUnitSelectShow( 2 );
                ui->radioButton_unit1->setText("   ");
                ui->radioButton_unit2->setText("(10 GSD)");

                if(ui->tableWidget_unit2->item(row,column)->text() == "")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "(10 GSD)")
                ui->radioButton_unit2->setChecked(true);

            }
            break;
            case 12:  //PCT
            {

                setUnitSelectShow( 2 );
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("mL/L");

                if(ui->tableWidget_unit2->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "mL/L")
                ui->radioButton_unit2->setChecked(true);

            }
            break;
            case 13:  //P-LCC
            {

                setUnitSelectShow( 4 );
                ui->radioButton_unit1->setText("10^9/L");
                ui->radioButton_unit2->setText("10^3/uL");
                ui->radioButton_unit3->setText("10^4/uL");
                ui->radioButton_unit4->setText("/nL");

                if(ui->tableWidget_unit2->item(row,column)->text() == "10^9/L")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "10^3/uL")
                ui->radioButton_unit2->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "10^4/uL")
                ui->radioButton_unit3->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "/nL")
                ui->radioButton_unit4->setChecked(true);
            }
            break;
            case 14:  //P-LCR
            {

                setUnitSelectShow( 2 );
                ui->radioButton_unit1->setText("%");
                ui->radioButton_unit2->setText("   ");

                if(ui->tableWidget_unit2->item(row,column)->text() == "%")
                ui->radioButton_unit1->setChecked(true);
                else if(ui->tableWidget_unit2->item(row,column)->text() == "")
                ui->radioButton_unit2->setChecked(true);

            }
            break;
        }
    }
}

void ParamUnitSetView::radioUnitSelect1()
{
   QString strUnit = ui->radioButton_unit1->text();

   switch(m_selectFlg)
   {
       case 1: setUnitText( strUnit, "***.**" ); break;
       case 2: setUnitText( strUnit, "***.**" ); break;
       case 3: setUnitText( strUnit, "***.**" ); break;
       case 4: setUnitText( strUnit, "***.**" ); break;
       case 5: setUnitText( strUnit, "***.**" ); break;
       case 6: setUnitText( strUnit, "***.**" ); break;
       case 7: setUnitText( strUnit, "**.*" ); break;
       case 8: setUnitText( strUnit, "**.*" ); break;
       case 9: setUnitText( strUnit, "**.*" ); break;
       case 10: setUnitText( strUnit, "**.*" ); break;
       case 11: setUnitText( strUnit, "**.*" ); break;
       case 12: setUnitText( strUnit, "***.**" ); break;
       case 13: setUnitText( strUnit, "**.*" ); break;
       case 14: setUnitText( strUnit, "***.**" ); break;
       case 15: setUnitText( strUnit, "**.*" ); break;
       case 16: setUnitText( strUnit, "**.**" ); break;  //rbc
       case 17: setUnitText( strUnit, "***" ); break;
       case 18: setUnitText( strUnit, "**.*" ); break;
       case 19: setUnitText( strUnit, "***.*" ); break;
       case 20: setUnitText( strUnit, "***.*" ); break;
       case 21: setUnitText( strUnit, "****" ); break;  //mchc
       case 22: setUnitText( strUnit, "**.*" ); break;
       case 23: setUnitText( strUnit, "***.*" ); break;
       case 24: setUnitText( strUnit, "****" ); break;  //plt
       case 25: setUnitText( strUnit, "**.*" ); break;
       case 26: setUnitText( strUnit, "**.*" ); break;
       case 27: setUnitText( strUnit, "*.***" ); break;
       case 28: setUnitText( strUnit, "****" ); break;
       case 29: setUnitText( strUnit, "**.*" ); break;
   }



}

void ParamUnitSetView::radioUnitSelect2()
{
    QString strUnit = ui->radioButton_unit2->text();

    switch(m_selectFlg)
    {
        case 1: setUnitText( strUnit, "***.**" ); break;
        case 2: setUnitText( strUnit, "***.**" ); break;
        case 3: setUnitText( strUnit, "***.**" ); break;
        case 4: setUnitText( strUnit, "***.**" ); break;
        case 5: setUnitText( strUnit, "***.**" ); break;
        case 6: setUnitText( strUnit, "***.**" ); break;
        case 7: setUnitText( strUnit, "*.***" ); break;
        case 8: setUnitText( strUnit, "*.***" ); break;
        case 9: setUnitText( strUnit, "*.***" ); break;
        case 10: setUnitText( strUnit, "*.***" ); break;
        case 11: setUnitText( strUnit, "*.***" ); break;
        case 12: setUnitText( strUnit, "***.**" ); break;
        case 13: setUnitText( strUnit, "*.***" ); break;
        case 14: setUnitText( strUnit, "***.**" ); break;
        case 15: setUnitText( strUnit, "*.***" ); break;
        case 16: setUnitText( strUnit, "**.**" ); break; //rbc
        case 17: setUnitText( strUnit, "**.*" ); break;
        case 18: setUnitText( strUnit, "*.***" ); break;
        case 19: setUnitText( strUnit, "***.*" ); break;
        case 20: setUnitText( strUnit, "**.**" ); break;
        case 21: setUnitText( strUnit, "***.*" ); break;  //mchc
        case 22: setUnitText( strUnit, "*.***" ); break;
        case 23: setUnitText( strUnit, "***.*" ); break;
        case 24: setUnitText( strUnit, "****" ); break;   //plt
        case 25: setUnitText( strUnit, "**.*" ); break;
        case 26: setUnitText( strUnit, "**.*" ); break;
        case 27: setUnitText( strUnit, "*.**" ); break;
        case 28: setUnitText( strUnit, "****" ); break;
        case 29: setUnitText( strUnit, "*.***" ); break;
    }
}


void ParamUnitSetView::radioUnitSelect3()
{
    QString strUnit = ui->radioButton_unit3->text();

    switch(m_selectFlg)
    {
        case 1: setUnitText( strUnit, "****.*" ); break;
        case 2: setUnitText( strUnit, "****.*" ); break;
        case 3: setUnitText( strUnit, "****.*" ); break;
        case 4: setUnitText( strUnit, "****.*" ); break;
        case 5: setUnitText( strUnit, "****.*" ); break;
        case 6: setUnitText( strUnit, "****.*" ); break;
        case 7: setUnitText( strUnit, "" ); break;
        case 8: setUnitText( strUnit, "" ); break;
        case 9: setUnitText( strUnit, "" ); break;
        case 10: setUnitText( strUnit, "" ); break;
        //case 11: setUnitText( strUnit, "" ); break;//
        case 12: setUnitText( strUnit, "****.*" ); break;
        //case 13: setUnitText( strUnit, "" ); break;//
        case 14: setUnitText( strUnit, "****.*" ); break;  //
        //case 15: setUnitText( strUnit, "" ); break;//
        case 16: setUnitText( strUnit, "****" ); break;  //rbc
        case 17: setUnitText( strUnit, "**.*" ); break;
        case 18: setUnitText( strUnit, "*.***" ); break;
        //case 19: setUnitText( strUnit, "" ); break;     //
        case 20: setUnitText( strUnit, "****" ); break;
        case 21: setUnitText( strUnit, "***.*" ); break;  //mchc
        //case 22: setUnitText( strUnit, "" ); break;//
        //case 23: setUnitText( strUnit, "" ); break;//
        case 24: setUnitText( strUnit, "***.*" ); break;  //plt
        //case 25: setUnitText( strUnit, "" ); break;      //mpv
        //case 26: setUnitText( strUnit, "" ); break;//
        //case 27: setUnitText( strUnit, "" ); break;//
        case 28: setUnitText( strUnit, "****.*" ); break;
        //case 29: setUnitText( strUnit, "" ); break;
    }
}

void ParamUnitSetView::radioUnitSelect4()
{
    QString strUnit = ui->radioButton_unit4->text();

    switch(m_selectFlg)
    {
        case 1: setUnitText( strUnit, "***.**" ); break;
        case 2: setUnitText( strUnit, "***.**" ); break;
        case 3: setUnitText( strUnit, "***.**" ); break;
        case 4: setUnitText( strUnit, "***.**" ); break;
        case 5: setUnitText( strUnit, "***.**" ); break;
        case 6: setUnitText( strUnit, "***.**" ); break;
        case 7: setUnitText( strUnit, "" ); break;
        case 8: setUnitText( strUnit, "" ); break;
        case 9: setUnitText( strUnit, "" ); break;
        case 10: setUnitText( strUnit, "" ); break;
        //case 11: setUnitText( strUnit, "" ); break;      //
        case 12: setUnitText( strUnit, "***.**" ); break;
        //case 13: setUnitText( strUnit, "" ); break;      //
        case 14: setUnitText( strUnit, "***.**" ); break;  //
        //case 15: setUnitText( strUnit, "" ); break;//
        case 16: setUnitText( strUnit, "**.**" ); break;  //rbc
        //case 17: setUnitText( strUnit, "" ); break;//
        //case 18: setUnitText( strUnit, "" ); break;//
        //case 19: setUnitText( strUnit, "" ); break;//
        //case 20: setUnitText( strUnit, "" ); break;//
        //case 21: setUnitText( strUnit, "" ); break;//
        //case 22: setUnitText( strUnit, "" ); break;//
        //case 23: setUnitText( strUnit, "" ); break;//
        case 24: setUnitText( strUnit, "****" ); break;  //plt
        //case 25: setUnitText( strUnit, "" ); break;//
        //case 26: setUnitText( strUnit, "" ); break;//
        //case 27: setUnitText( strUnit, "" ); break;//
        case 28: setUnitText( strUnit, "****" ); break;
        //case 29: setUnitText( strUnit, "" ); break;
    }
}

void ParamUnitSetView::setUnitText(QString str1, QString str2)
{
    if( m_selectFlg <= 15 )
    {
        ui->tableWidget_unit1->item(m_selectFlg, 1)->setText( str1.trimmed() );
        ui->tableWidget_unit1->item(m_selectFlg, 2)->setText( str2 );
    }
    else
    {
        ui->tableWidget_unit2->item(m_selectFlg-15, 1)->setText( str1.trimmed() );
        ui->tableWidget_unit2->item(m_selectFlg-15, 2)->setText( str2 );
    }
}

void ParamUnitSetView::setUnitSelectShow(int index)
{
    if( 0 == index )
    {
        ui->label_unitSel->hide();
        ui->radioButton_unit1->hide();
        ui->radioButton_unit2->hide();
        ui->radioButton_unit3->hide();
        ui->radioButton_unit4->hide();
    }
    if( 2 == index )
    {
        ui->label_unitSel->show();
        ui->radioButton_unit1->show();
        ui->radioButton_unit2->show();
        ui->radioButton_unit3->hide();
        ui->radioButton_unit4->hide();
    }
    if( 3 == index )
    {
        ui->label_unitSel->show();
        ui->radioButton_unit1->show();
        ui->radioButton_unit2->show();
        ui->radioButton_unit3->show();
        ui->radioButton_unit4->hide();
    }
    if( 4 == index )
    {
        ui->label_unitSel->show();
        ui->radioButton_unit1->show();
        ui->radioButton_unit2->show();
        ui->radioButton_unit3->show();
        ui->radioButton_unit4->show();
    }
    ui->radioButton_unit5->hide();
}
